<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .center{
            width: 1200px;
            margin: 0 auto;
        }
        #footer_center p{
            margin: 0;
        }
        #footer_center h3{
            color: white;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <!--头,引入my-header.js-->
        <my-header></my-header>
        <!--中间,主要内容部分-->
        <el-main style="background-image: url('http://rvg6mjj7z.hn-bkt.clouddn.com/img/login.gif');
                    height: 500px;background-size: cover;
                    background-position: center">
            <el-card style="width: 500px;height: 300px;;margin: 50px auto">
                <el-form label-width="80px" style="width: 400px;margin: 50px auto">
                    <el-form-item label="用户名">
                        <el-input type="text" placeholder="请输入用户名" v-model="user.username"></el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-input type="text" placeholder="请输入密码"
                                  @keydown.native.enter="login()" v-model="user.password"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="login()" >登录</el-button>
                        <el-button type="primary" @click="reg()">注册</el-button>
                    </el-form-item>

                </el-form>
            </el-card>
        </el-main>
        <!--脚-->
        <el-footer style="height: 350px;background-color: darkgrey;padding:50px 0">
            <my-footer></my-footer>
        </el-footer>
    </el-container>
</div>
</body>
<!--import axios-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入自己的js文件-->
<script src="js/my-header.js"></script>
<script src="js/my-footer.js"></script>


<script>
    let v = new Vue({
        el: '#app',
        data:{
            user:{username:"",password:""}
        },
        methods: {
            login(){
                //发出异步的post请求
                axios.post("/v1/users/login",v.user).then(function (response) {
                    if (response.data.code==1){
                        alert("登陆成功！")
                        //把用户信息的对象保存到localStorage
                        localStorage.user = JSON.stringify(response.data.data);
                        history.back();//返回上一页面
                    }else{
                        v.$message.error(response.data.msg)
                    }
                })
            },
            reg(){
                window.location.href = 'reg.html';
            }
        }
    })
</script>
</html>